package com.kczd.adapter;

import java.util.ArrayList;
import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.kczd.fragment.OrderFinishedFragment;
import com.kczd.fragment.OrderOverFragment;
import com.kczd.fragment.OrderNotFragment;


public class OrderPagerAdapter extends FragmentPagerAdapter {
	
	private List<Fragment> fragments;//创建fragment集合
	private int mChildCount;
	
	public OrderPagerAdapter(FragmentManager fm) {
		super(fm);
		fragments=new ArrayList<Fragment>();
		fragments.add(new OrderNotFragment());//已预约订单
		fragments.add(new OrderFinishedFragment());//已完成订单
		fragments.add(new OrderOverFragment());//已取消订单

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return fragments.size();
	}
	//注意重载方法  要选择有ViewGroup 的
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		Fragment itemFragment=(Fragment) super.instantiateItem(container,position);
		return itemFragment;
	}
	@Override
	public Fragment getItem(int positoin) {
		return fragments.get(positoin);
	}
	
	@Override
	public void notifyDataSetChanged() {
	    mChildCount = getCount();
	    super.notifyDataSetChanged();
	}

	@Override
	public int getItemPosition(Object object) {
	    if (mChildCount > 0) {
	        mChildCount--;
	        return POSITION_NONE;
	    }
	    return super.getItemPosition(object);
	}
}
